package cn.itcast.demo.mq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 虎哥
 */
public class ConnectionUtils {

    public static Connection getConnection() throws IOException, TimeoutException {
        // 建立MQ的连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        // 设置连接参数
        factory.setHost("192.168.150.101");
        factory.setPort(5672);
        factory.setUsername("itcast");
        factory.setPassword("itcast");
        factory.setVirtualHost("/");
        // 获取连接
        return factory.newConnection();
    }
}
